<template>
<a-card  class="info" title="员工薪酬信息表">
  <div>
    <a-row :gutter="24">
      <a-col :xl="6" :lg="7" :md="8" :sm="24">
        <a-form-item label="工资条所属期间">
          <a-range-picker
              :allowClear="false"
              v-model="date"
              format="YYYY-MM"
              style="width: 100%"
              @change="onDateChange"/>
        </a-form-item>
      </a-col>
    </a-row>
    <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :loading="confirmLoading"
        class="j-table-force-nowrap"
        :pagination="ipagination"
        @change="handleChange"
        >
        <!-- <template slot="accumulatedIncome">
          <span>{{ queryParam.date.substr(0,4) }}年累计收入</span>
        </template>
        <template slot="insuranceDeduction">
          <span>{{ queryParam.date.substr(0,4) }}年五险一金累计扣款</span>
        </template>

        <template slot="personalIncomeTax">
          <span>{{ queryParam.date.substr(0,4) }}年累计个税专项附加扣除金额</span>
        </template>
        <template slot="payableInAdvance">
          <span>{{ queryParam.date.substr(0,4) }}年应预缴个人所得税</span>
        </template>
        <template slot="individualIncomeTaxAmount">
          <span>{{ queryParam.date.substr(0,4) }}年已预缴个人所得税金额</span>
        </template> -->
    </a-table>
  </div>
  </a-card>
</template>

<script>

  import { getAction } from '@/api/manage'
  import moment from 'moment'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'

  export default {
    name: 'ErpPayrollLedgerDetail',
    mixins: [JeecgListMixin, DisabledAuthFilterMixin],
    components: {
    },
    data () {
      return {
        date:[moment(new Date()).subtract(1,'months').format("YYYY-MM"),moment(new Date()).subtract(1,'months').format("YYYY-MM")],
        queryParam:{
          date_begin:moment(new Date()).subtract(1,'months').format('YYYY-MM'),
          date_end:moment(new Date()).subtract(1,'months').format('YYYY-MM'),
        },
        yearShowOne:false,
        model: [],
        id: '',
        url: {
          list: "/api/erp/hr/salary/erpHrSalaryPayslipRecord/querySalaryByEmployeeId",
        },
        confirmLoading: false,
        iconStyle:{"font-size":"20px"},
        /* 排序参数 */
          isorter: {
          },
        initCol:[],
        // 列定义
        columns: [
          // {
          //   title:'工资条制作人',
          //   align:"center",
          //   dataIndex: 'createBy_dictText',
          // },
          {
            title:'工资期间',
            align:"center",
            dataIndex: 'salaryDate',
          },
          {
            title:'工号',
            align:"center",
            dataIndex: 'employeeNo',
          },
          {
            title:'姓名',
            align:"center",
            dataIndex: 'employeeName',
          },
          {
            title:'人员状态',
            align:"center",
            dataIndex: 'employeeStatus',
          },
          {
            title:'身份证号码',
            align:"center",
            dataIndex: 'idCardNo',
          },
          {
            title:'所属公司',
            align:"center",
            dataIndex: 'company',
          },
          {
            title:'所属团队',
            align:"center",
            dataIndex: 'team',
          },
          {
            title:'所属团队部门',
            align:"center",
            dataIndex: 'depart',
          },
          {
            title:'所属团队岗位名称',
            align:"center",
            dataIndex: 'post',
          },
          {
            title: '岗位属性',
            align: 'center',
            width: 100,
            ellipsis: true,
            dataIndex: 'postCate',

          },
          {
            title: '职级',
            align: 'center',
            width: 100,
            ellipsis: true,
            dataIndex: 'postRank',
          },
          {
            title:'入职时间',
            align:"center",
            dataIndex: 'joinDate',
          },
          {
            title:'转正时间',
            align:"center",
            dataIndex: 'probationDate',
          },
          {
            title:'最后一次岗位变化引起的薪级调整日期',
            align:"center",
            dataIndex: 'lastDate',
          },
          {
            title:'最后工作日',
            align:"center",
            dataIndex: 'lastWorkDate',
          },
          {
            title:'薪级',
            align:"center",
            dataIndex: 'salaryScale',
          },
          {
            title:'基础工资',
            align:"center",
            dataIndex: 'basicSalary',
          },
          {
            title:'年功工资',
            align:"center",
            dataIndex: 'seniorityWage',
          },
          {
            title:'等级工资',
            align:"center",
            dataIndex: 'gradedWages',
          },
          {
            title:'岗位工资',
            align:"center",
            dataIndex: 'postWages',
          },
          {
            title:'加1项',
            align:"center",
            dataIndex: 'addItem',
          },
          {
            title:'预发绩效',
            align:"center",
            dataIndex: 'preReleasePerformance',
          },
          {
            title:'预发绩效补发',
            align:"center",
            dataIndex: 'preReleasePerformanceReissue',
          },
          {
            title:'工龄工资',
            align:"center",
            dataIndex: 'seniorityWages',
          },
          {
            title:'执业金',
            align:"center",
            dataIndex: 'practicingFee',
          },
          {
            title:'报告审核费',
            align:"center",
            dataIndex: 'reportReviewFee',
          },
          {
            title:'经营绩效',
            align:"center",
            dataIndex: 'managePerformance',
          },
          {
            title:'生产绩效',
            align:"center",
            dataIndex: 'productPerformance',
          },

          {
            title:'项目绩效',
            align:"center",
            dataIndex: 'projectPerformance',
          },
          {
            title:'效能工资',
            align:"center",
            dataIndex: 'efficiencySalary',
          },
          {
            title:'餐补',
            align:"center",
            dataIndex: 'mealAllowance',
          },
          {
            title:'住房补贴',
            align:"center",
            dataIndex: 'housingSubsidies',
          },
          {
            title:'通讯补贴',
            align:"center",
            dataIndex: 'communicationSubsidy',
          },
          {
            title:'外派补贴',
            align:"center",
            dataIndex: 'expatriateSubsidy',
          },
          {
            title:'专项支持费',
            align:"center",
            dataIndex: 'specialSupportFee',
          },
          {
            title:'公里数提现',
            align:"center",
            dataIndex: 'kilometersWithdrawal',
          },
          {
            title:'应收账款奖励',
            align:"center",
            dataIndex: 'accountsReceivableRewards',
          },
          {
            title:'宣传奖励',
            align:"center",
            dataIndex: 'promotionRewards',
          },
          {
            title:'其他奖励',
            align:"center",
            dataIndex: 'otherRewards',
          },
          {
            title:'前期已结算',
            align:"center",
            dataIndex: 'previouslySettled',
          },
          {
            title:'加班工资',
            align:"center",
            dataIndex: 'overtimeWage',
          },
          {
            title:'其他加项',
            align:"center",
            dataIndex: 'otherAdditions',
          },
          // {
          //   title:'试用期天数',
          //   align:"center",
          //   dataIndex: 'probationPeriodDays',
          // },
          {
            title:'试用期薪级工资扣款',
            align:"center",
            dataIndex: 'salaryLevelDuringProbationaryAmount',
          },
          {
            title:'缺勤扣款',
            align:"center",
            dataIndex: 'absenceDeduction',
          },
          // {
          //   title:'入离职缺勤天数',
          //   align:"center",
          //   dataIndex: 'resignationDays',
          // },
          // {
          //   title:'入离职缺勤扣款',
          //   align:"center",
          //   dataIndex: 'resignationAmount',
          // },
          // {
          //   title:'事假天数',
          //   align:"center",
          //   dataIndex: 'leaveDays',
          // },
          // {
          //   title:'事假扣款',
          //   align:"center",
          //   dataIndex: 'personalLeaveAmount',
          // },
          // {
          //   title:'病假天数',
          //   align:"center",
          //   dataIndex: 'sickLeaveDays',
          // },
          // {
          //   title:'病假扣款',
          //   align:"center",
          //   dataIndex: 'sickLeaveAmount',
          // },
          // {
          //   title:'产假天数',
          //   align:"center",
          //   dataIndex: 'maternityLeaveDays',
          // },
          // {
          //   title:'产假扣款',
          //   align:"center",
          //   dataIndex: 'maternityLeaveAmount',
          // },
          // {
          //   title:'迟到早退次数',
          //   align:"center",
          //   dataIndex: 'lateAndEarlyLeaveTime',
          // },
          // {
          //   title:'迟到早退扣款',
          //   align:"center",
          //   dataIndex: 'lateAndEarlyLeaveAmount',
          // },
          // {
          //   title:'缺卡次数',
          //   align:"center",
          //   dataIndex: 'missCardTime',
          // },
          // {
          //   title:'缺卡扣款',
          //   align:"center",
          //   dataIndex: 'missCardAmount',
          // },
          // {
          //   title:'旷工天数',
          //   align:"center",
          //   dataIndex: 'absenteeismDays',
          // },
          // {
          //   title:'旷工扣款',
          //   align:"center",
          //   dataIndex: 'absenteeismAmount',
          // },
          {
            title:'应收账款扣款',
            align:"center",
            dataIndex: 'receivableDeduction',
          },
          {
            title:'其他扣款',
            align:"center",
            dataIndex: 'otherAmount',
          },
          {
            title:'应发工资',
            align:"center",
            dataIndex: 'wagepayable',
          },
          // {
          //   align:"center",
          //   dataIndex: 'accumulatedIncome',
          //   scopedSlots: { title:'accumulatedIncome' }
          // },
          {
            title:'个人社保',
            align:"center",
            dataIndex: 'nextMonthSocialAmount',
          },
          {
            title:'个人公积金',
            align:"center",
            dataIndex: 'providentFundAmount',
          },
          // {
          //   align:"center",
          //   dataIndex: 'insuranceDeduction',
          //   scopedSlots: { title:'insuranceDeduction' }
          // },
          // {
          //   align:"center",
          //   dataIndex: 'personalIncomeTax',
          //   scopedSlots: { title:'personalIncomeTax' }
          // },
          // {
          //   align:"center",
          //   dataIndex: 'payableInAdvance',
          //   scopedSlots: { title:'payableInAdvance' }
          // },
          // {
          //   align:"center",
          //   dataIndex: 'individualIncomeTaxAmount',
          //   scopedSlots: { title:'individualIncomeTaxAmount' }
          // },
          {
            title:'本期应预缴个人所得税',
            align:"center",
            dataIndex: 'incomeTaxPayableInAdvance',
          },
          {
            title:'前期已发放',
            align:"center",
            dataIndex: 'previouslyDistributed',
          },
          {
            title:'实发工资',
            align:"center",
            dataIndex: 'netSalary',
          },
        ],
        dataSource: [],
        disableMixinCreated: true
      }
    },
    props: {
      employeeId: String
    },
    watch: {
      employeeId: {
        handler: function(val){
          console.log("222222222222",val);
          let initCol=this.columns;
          this.initCol=initCol;
          this.initDictConfig(val)
        },
        immediate: true
      },
      // BUG4233 查看多人员工档案信息，信息数据被覆盖
      $route(to, from) {
        this.initDictConfig(to.query.id)
      },
    },
    methods: {
      // 弹出日历和关闭日历的回调
      // openChangeOne(status){
      //     //status是打开或关闭的状态
      //     this.yearShowOne =  !this.yearShowOne
      // },
      onDateChange(date, dateString) {
        this.$set(this.queryParam,"date_begin",moment(dateString[0]).format('YYYY-MM'))
        this.$set(this.queryParam,"date_end",moment(dateString[1]).format('YYYY-MM'))
        this.date=[moment(dateString[0]).format('YYYY-MM'),moment(dateString[1]).format('YYYY-MM')]
        this.initDictConfig(this.employeeId)
      },
      // 得到年份选择器的值
      // panelChangeOne(value){
      //   this.$set(this.queryParam,"date",moment(value).format('YYYY'))
      //   console.log("11111111111",this.employeeId);
      //   this.initDictConfig(this.employeeId);
      //   this.yearShowOne =  !this.yearShowOne
      // },
      initDictConfig(id) {
        console.log(this.columns);
        const that = this
        this.columns=this.initCol;
        var params = this.getQueryParams() // 查询条件
        if(!id){
          return ;
        }
        params.employeeId=id;
        params.isDistribute="1";
        params.column=null;
        params.order=null;
        //params.date=params.date+"*"
        console.log(params);
        getAction(this.url.list,params).then((res) => {
          if (res.success) {
            const dataSource = res.result.records
            this.dataSource=dataSource;
            this.checkChange(this.dataSource);
          } else {
            that.$message.warning(res.message);
          }
        })
      },
      checkChange(dataList) {
        const columns = this.columns
        console.log(columns);
        const filterValue = columns.filter(item => {
          let data=dataList.filter(temp=>temp[item.dataIndex]!=null && temp[item.dataIndex]!="" );
            if(data.length>0){
              return true
            }
            return false
        })
        this.columns = filterValue
      },
      handleChange(pagination, filters, sorter) {
        // 分页、排序、筛选变化时触发
        this.filters = {}
        if (Object.keys(filters).length > 0) {
          for (let key in filters) {
            let value = filters[key].join(',')
            if (value) {
              if (key.indexOf('_dictText') != -1) {
                key = key.substring(0, key.indexOf('_dictText'))
              }
              this.filters[key] = value
            }
          }
        }
        if (Object.keys(sorter).length > 0) {
          this.isorter.column = sorter.field
          this.isorter.order = sorter.order == 'ascend' ? 'asc' : 'desc'
        }
        this.ipagination = pagination
        this.initDictConfig(this.employeeId)
      },
    }
  }
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';

.info {
  /deep/ .ant-card-head-title{
    flex: none;
    margin-right: 20px;
  }
  /deep/ .ant-card-extra{
    flex: 1;
    float: left;
  }
}
</style>
